package com.ktjiaoyu.t351.controller;

import com.ktjiaoyu.t351.entity.User;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName : HelloController
 * @Description :
 * @Author : Lzz
 * @Date: 2023/10/13 09:49:12
 */
@Controller
public class HelloController {

    @RequestMapping(value = "/hello",method = RequestMethod.POST)
    public ModelAndView hello(@RequestBody User user) {
        System.out.println(user.getId()+":"+user.getUserName());
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("name", "土豆");
        modelAndView.setViewName("hello");
        return modelAndView;
    }

    @RequestMapping("/index")
    public String index(){

        return "redirect:index.jsp";
    }

    /**
     * 跳转相同Controller下的不同的方法
     * @return
     */
    @RequestMapping("/goIndex")
    public String goIndex(){

        return "forward:/index";
    }

    /**
     * 跳转不同Controller下的方法
     * @return
     */
    @RequestMapping("/goTest")
    public String goTest(){

        return "forward:/test/toTest";
    }


}
